package cn.laike.modules.dev.controller.api;


import java.io.BufferedReader;
import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hp.hpl.sparta.xpath.ParentNodeTest;

import cn.laike.common.utils.DateUtils;
import cn.laike.common.utils.HttpRequest;
import cn.laike.common.utils.IPUtils;
import cn.laike.common.utils.ImageUtils;
import cn.laike.common.utils.R;
import cn.laike.common.utils.XMLUtils;
import cn.laike.common.utils.wxpay.CommonUtil;
import cn.laike.common.utils.wxpay.WxPayHelper;
import cn.laike.modules.dev.controller.InvoiceController;
import cn.laike.modules.dev.entity.BreakfastCouponEntity;
import cn.laike.modules.dev.entity.CityEntity;
import cn.laike.modules.dev.entity.ConfigEntity;
import cn.laike.modules.dev.entity.EarnestMoneyOrderEntity;
import cn.laike.modules.dev.entity.HotelEntity;
import cn.laike.modules.dev.entity.HotelRoomEntity;
import cn.laike.modules.dev.entity.InvoiceEntity;
import cn.laike.modules.dev.entity.MemberEntity;
import cn.laike.modules.dev.entity.OrderEntity;
import cn.laike.modules.dev.entity.PrinterEntity;
import cn.laike.modules.dev.entity.RecommendMoneyLogEntity;
import cn.laike.modules.dev.entity.WithdrawalLogEntity;
import cn.laike.modules.dev.service.BannerService;
import cn.laike.modules.dev.service.BreakfastCouponService;
import cn.laike.modules.dev.service.CityService;
import cn.laike.modules.dev.service.EarnestMoneyOrderService;
import cn.laike.modules.dev.service.HotelRoomBannerService;
import cn.laike.modules.dev.service.HotelRoomService;
import cn.laike.modules.dev.service.HotelService;
import cn.laike.modules.dev.service.InvoiceService;
import cn.laike.modules.dev.service.MemberService;
import cn.laike.modules.dev.service.OrderService;
import cn.laike.modules.dev.service.PrinterService;
import cn.laike.modules.dev.service.RecommendMoneyLogService;
import cn.laike.modules.dev.service.WithdrawalLogService;
import cn.laike.modules.dev.utils.DevCacheUtils;
import cn.laike.modules.dev.utils.DevUtils;
import cn.laike.modules.dev.utils.PrinterUtils;
import net.sf.json.JSONObject;


/**
 * 酒店预订 
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/api/hotel")
public class ApiHotelController {
	@Autowired
    private CityService cityService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private HotelService hotelService;
	@Autowired
    private HotelRoomService hotelRoomService;
	@Autowired
	private HotelRoomBannerService hotelRoomBannerService;
	
	@Autowired
    private OrderService orderService;
	@Autowired
    private PrinterService printerService;
	@Autowired
    private EarnestMoneyOrderService earnestMoneyOrderService;
	@Autowired
	private BannerService bannerService;
	@Autowired
    private BreakfastCouponService breakfastCouponService;
	
	@Autowired
    private InvoiceService invoiceService;
	@Autowired
    private RecommendMoneyLogService recommendMoneyLogService;
	@Autowired
    private WithdrawalLogService withdrawalLogService;
	
	
	/**
	 * 获取所属酒店的城市列表
	 * http://localhost/api/hotel/get_city_by_name?name=邯郸
	 * @param uid
	 * @return
	 */
	@RequestMapping(value="get_city_by_name")	
	public R get_city_by_name(@RequestParam(value="uid",defaultValue="0")Long uid,
			@RequestParam(value="name",defaultValue="")String name){
		CityEntity city = cityService.getCityByName(name);
		Map<String, Integer> hotel = hotelService.getHotelCount(uid);
		System.out.println("酒店："+hotel.get("hotel_count"));
		ConfigEntity config = DevCacheUtils.getConfig(uid);
		List bannerList = bannerService.queryBannerList(uid);
		if(city != null && city.getId() > 0) {
			return R.ok().put("cityId", city.getId()).put("hotelCount", hotel.get("hotel_count")).put("hotelId", hotel.get("hotel_id")).put("bg", "http://laike.hbweiyinqing.cn/userfiles/config/"+config.getBg()).put("bannerList", bannerList).put("devname", config.getName());
		}else {
			return R.ok().put("cityId", -1).put("hotelCount", hotel.get("hotel_count")).put("hotelId", hotel.get("hotel_id")).put("bg", "http://laike.hbweiyinqing.cn/userfiles/config/"+config.getBg()).put("bannerList", bannerList).put("devname", config.getName());
		}
	} 
	
	/**
	 * 获取所属酒店的城市列表
	 * http://localhost/api/hotel/query_hotel_city_list?uid=1
	 * @param uid
	 * @return
	 */
	@RequestMapping(value="query_hotel_city_list")	
	public R query_hotel_city_list(@RequestParam(value="uid",defaultValue="0")Long uid){
		List<CityEntity> list = cityService.queryHotelCityList(uid);
		List<Map>  citylist = Lists.newArrayList();;
		Map<String,List<Map>> parent = Maps.newConcurrentMap();
		
		for (CityEntity city : list) {
			List<Map>  childList = null;
			if(parent.containsKey(city.getHeadChar())) {
				childList = parent.get(city.getHeadChar());
			}else {
				childList = Lists.newArrayList();
				Map map = Maps.newConcurrentMap();
				map.put("head_char", city.getHeadChar());
				map.put("child_list", childList);
				citylist.add(map);
				parent.put(city.getHeadChar(), childList);
			}
			Map map = Maps.newConcurrentMap();
			map.put("id", city.getId());
			map.put("name", city.getName());
			childList.add(map);
		}
		return R.ok().put("list", citylist);
	} 
	
	/**
	 *  根据所属城市酒店列表
	 *  http://localhost/api/hotel/query_hotel_list?uid=1&cityId=1&name=
	 * @param uid
	 * @param cityId
	 * @return
	 */
	@RequestMapping(value="query_hotel_list")	
	public R query_hotel_list(@RequestParam(value="uid",defaultValue="0")Long uid,
			@RequestParam(value="cityId",defaultValue="0")Integer cityId,
			@RequestParam(value="name",defaultValue="")String name){
		return R.ok().put("list", hotelService.queryHotelList(uid, cityId, name));
	} 
	
	/**
	 * 获取酒店详情
	 * http://localhost/api/hotel/get_hotel_info?id=1
	 * @param id
	 * @return
	 */
	@RequestMapping(value="get_hotel_info")	
	public R get_hotel_info(@RequestParam(value="id",defaultValue="0")Integer id){
		HotelEntity hotel = hotelService.getHotel(id);
		if(hotel.getIntro() != null) {
			hotel.setIntro(hotel.getIntro().replace("\n", "<br/>"));
		}
		return R.ok().put("i", hotel).put("l", hotelRoomBannerService.queryBannerList(id, 0));
	} 
	
	@RequestMapping(value="get_hotel_room")	
	public R get_hotel_room(@RequestParam(value="hotelId",defaultValue="0")Integer hotelId,@RequestParam(value="hotelRoomId",defaultValue="0")Integer hotelRoomId){
		return R.ok().put("l", hotelRoomBannerService.queryBannerList(hotelId, hotelRoomId));
	} 
	
	/**
	 *  获取客房列表
	 * http://localhost/api/hotel/query_hotel_room_list?hotelRoomId=1&start=2019-02-25&start=2019-02-26
	 * @param hotelId
	 * @return
	 */
	@RequestMapping(value="query_hotel_room_list")	
	public R query_hotel_room_list(@RequestParam(value="hotelId",defaultValue="0")Integer hotelId,
			@RequestParam(value="start",defaultValue="")String start,
			@RequestParam(value="end",defaultValue="")String end){
	
		String isStock = "";
		String today = DateUtils.format(new Date());
		if(StringUtils.isNotEmpty(start) && StringUtils.isNotEmpty(end)) {
			if(today.equals(start)) {
				isStock = "today";
			}
			int days = DateUtils.differentDays(DateUtils.stringToDate(start), DateUtils.stringToDate(end));
			List<Map> list = hotelRoomService.queryHotelRoomList(hotelId,days,isStock);
			for (Map map : list) {
				if(map.containsKey("intro")) {
					String intro = map.get("intro").toString().replace("\n", "<br/>");
					map.put("intro", intro);
				}
			}
			return R.ok().put("list", list);
		}else {
			return R.error("请选择预定时间");
		}
		
	}
	
	
	/**
     * 1创建预定订单
     * http://localhost/api/hotel/pre_create_order?hotelRoomId=1&openid=oTa4I0eOj638wk74MDv3S3zPKWnU
     * @param request
     * @param response
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "pre_create_order")
    public R pre_create_order(OrderEntity order,
    		@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date start,
			@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date end) {
        try {

        	MemberEntity member = memberService.getMemberByOpenid(order.getOpenid());
    		if(member !=null && StringUtils.isNotEmpty(member.getMobile())){
    			HotelRoomEntity hotelRoom = hotelRoomService.selectById(order.getHotelRoomId());
    			HotelEntity hotel = hotelService.selectById(hotelRoom.getHotelId());

				order.setHotelId(hotelRoom.getId());
				order.setHotelName(hotel.getName());
				order.setHotelRoomId(hotelRoom.getId());
				order.setHotelRoomName(hotelRoom.getName());
				order.setNumber(1);
				if(hotelRoom.getType() == 1) {
					start = new Date();
					end = new Date();
					order.setDays(1);
				}else {
					order.setDays(DateUtils.differentDays(start, end));
				}
				Double totalPrice = hotelRoom.getMoney() * order.getNumber()*order.getDays();
				order.setTotalPrice(totalPrice);
				order.setPrice(totalPrice);
				order.setNumber(1);
				order.setHotelRoomType(hotelRoom.getType());
				order.setName(member.getName());
				order.setMobile(member.getMobile());
	
				order.setCreateTime(new Date());
				
    			return R.ok("OK").put("order", order).put("start", DateUtils.format(start)).put("end", DateUtils.format(end));
    		}else{
    			return R.error("请注册会员！");
    		}
			
		} catch (Exception e) {
			return R.error("参数异常!");
		}
    } 
    
    /**
     * http://localhost/api/hotel/add_number?hotelRoomId=1&number=27&start=2019-02-25
     * @param hotelRoomId
     * @param number
     * @param start
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "add_number")
    public R add_number(@RequestParam(value="hotelRoomId",defaultValue="0")Integer hotelRoomId,
    		@RequestParam(value="number",defaultValue="0")Integer number,
    		@RequestParam(value="days",defaultValue="0")Integer days,
			@RequestParam(value="start",defaultValue="")String start){
	
		String isstock = "";
		String today = DateUtils.format(new Date());
		HotelRoomEntity hotelRoom = hotelRoomService.selectById(hotelRoomId);
		BigDecimal bg = new BigDecimal(hotelRoom.getMoney()*number*days);
		double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		if(today.equals(start)) {
			if(hotelRoom.getStock() >= number) {
				return R.ok().put("isstock", true).put("totalPrice", f1);
			}else {
				return R.ok().put("isstock", false);
			}
		}else {
			return R.ok().put("isstock", true).put("totalPrice", f1);
		}
	}
	
	/**
     * 创建订单
     * http://localhost/api/hotel/create_order?hotelRoomId=1&number=2&openid=ogDOQ4hhxSTBe4z8fyTtjBNy-0lg&start=2019-02-26&end=2019-02-27
     * @param request
     * @param response
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "create_order")
    public R createOrder(OrderEntity order,
    		@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date start,
			@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date end,
			HttpServletRequest request) {
        try {

        	MemberEntity member = memberService.getMemberByOpenid(order.getOpenid());
    		if(member !=null && StringUtils.isNotEmpty(member.getMobile())){
    			HotelRoomEntity hotelRoom = hotelRoomService.selectById(order.getHotelRoomId());
    			HotelEntity hotel = hotelService.selectById(hotelRoom.getHotelId());
    			if(hotelRoom.getStock() >= order.getNumber()) {
    				//订单号
    	        	String orderNo = CommonUtil.getOrderNo(6);
    	        	//会员卡名称
    	        	String body = hotelRoom.getName();
    	        	//金额
    	        	Double money = hotelRoom.getMoney();

    				order.setUid(hotelRoom.getUid());
    				order.setHotelId(hotel.getId());
    				order.setHotelName(hotel.getName());
    				order.setHotelRoomId(hotelRoom.getId());
    				order.setHotelRoomName(hotelRoom.getName());
    				
    				//order.setTotalPrice()(money);
    				//order.setType(1);
    				if(StringUtils.isEmpty(order.getName())) {
    					order.setName(member.getName());
    				}
    				order.setNickname(member.getNickname());
    				if(StringUtils.isEmpty(order.getMobile())) {
    					order.setMobile(member.getMobile());
    				}
    				if(StringUtils.isNotEmpty(member.getParentOpenid())) {
    					order.setParentOpenid(member.getParentOpenid());
    					order.setParentName(member.getParentName());
    				}
    				order.setHotelRoomType(hotelRoom.getType());
    				order.setAvatar(member.getAvatar());
    				order.setStatus(0);
    				order.setOrderNo(orderNo);
    				order.setCreateTime(new Date());
    				
    				if(hotelRoom.getType() == 1) {
    					order.setStartDate(new Date());
        				order.setEndDate(new Date());
    					order.setDays(1);
    				}else {
    					order.setStartDate(start);
        				order.setEndDate(end);
    					order.setDays(DateUtils.differentDays(start, end));
    				}
    				Double totalPrice = hotelRoom.getMoney() * order.getNumber()*order.getDays();
    				order.setTotalPrice(totalPrice);
    				order.setPrice(totalPrice);
    				order.setBalance(0d);
    				order.setMoney(0d);
    				order.setRefundFee(0d);
    				
    				
    				Map jsApi = createJsApi(hotelRoom.getUid(), body, orderNo, totalPrice, order.getOpenid(), request);
    				order.setPrepayId(jsApi.get("package").toString().replace("prepay_id=", ""));
    				orderService.insert(order);
        			return R.ok("OK").put("orderNo", orderNo).put("jsapi", jsApi);
    			}else {
    				return R.error("创建订单失败，库存不足！");
    			}
				
    		
    		}else{
    			return R.error("请注册会员！");
    		}
			
		} catch (Exception e) {
			return R.error("参数异常!");
		}
    } 
	
	
	/**
     * 生成访问小程序支付jsapi
     * 
     * @param request
     * @return
     */
 	@SuppressWarnings("rawtypes")
	private Map createJsApi(Long uid,String body,String orderNo,Double money,String openid,HttpServletRequest request)throws Exception {
		ConfigEntity config = DevCacheUtils.getConfig(uid);
 		// 微信支付jsapi 生成json
		String nonceStr = CommonUtil.CreateNoncestr();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + request.getContextPath();
		WxPayHelper wxPayHelper = new WxPayHelper();
		wxPayHelper.setAppId(config.getAppId());
		wxPayHelper.setMchId(config.getMchId());
		
		wxPayHelper.SetParameter("nonce_str", nonceStr);
		wxPayHelper.SetParameter("body", body);
		wxPayHelper.SetParameter("out_trade_no", orderNo);
		wxPayHelper.SetParameter("total_fee",String.format("%.0f",money*100));
		wxPayHelper.SetParameter("spbill_create_ip",
				IPUtils.getIpAddr(request));
		wxPayHelper.SetParameter("notify_url", basePath
				+ "/api/hotel/wxNotify");
		wxPayHelper.SetParameter("trade_type", "JSAPI");
		wxPayHelper.SetParameter("openid", openid);
		wxPayHelper.setApiKey(config.getApiKey());
		return wxPayHelper.createPayByJSAPI();
 	}
 	
 	/**
 	 * 微信支付回调
 	 * http://localhost:8080/admin/api/member/wxNotify
 	 * @param request
 	 * @param response
 	 * @return
 	 * @throws Exception
 	 */
 	@RequestMapping(value = "wxNotify")
 	public String wxNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
 		//<xml><appid><![CDATA[wxad3e0062b1cbdaaf]]></appid><bank_type><![CDATA[CFT]]></bank_type><cash_fee><![CDATA[1]]></cash_fee><fee_type><![CDATA[CNY]]></fee_type><is_subscribe><![CDATA[N]]></is_subscribe><mch_id><![CDATA[1400343402]]></mch_id><nonce_str><![CDATA[VQweZcmzsBxNlSyH]]></nonce_str><openid><![CDATA[oLe7z0PJdls4IzUmS82rrHcq3bIA]]></openid><out_trade_no><![CDATA[201812290934867653]]></out_trade_no><result_code><![CDATA[SUCCESS]]></result_code><return_code><![CDATA[SUCCESS]]></return_code><sign><![CDATA[ACE389049C3102FE95746469BE2BA913]]></sign><time_end><![CDATA[20181229093627]]></time_end><total_fee>1</total_fee><trade_type><![CDATA[JSAPI]]></trade_type><transaction_id><![CDATA[4200000232201812290072540704]]></transaction_id></xml>
 		StringBuffer stringBuffer = new StringBuffer();
 		BufferedReader bReader = request.getReader();
 		String line = "";
 		while ((line = bReader.readLine()) != null) {
 			stringBuffer.append(line);
 		}
 		Map<String, String> xmlMap = XMLUtils.xml2Map(stringBuffer.toString());

 		String resXml = null;

 		if ("SUCCESS".equals(xmlMap.get("xml.result_code"))) {
 			String orderNo = xmlMap.get("xml.out_trade_no");
 			String tradeNo = xmlMap.get("xml.transaction_id");
 			
			OrderEntity order =  orderService.getByOrderNo(orderNo);
 			if(order != null && order.getStatus() != null && order.getStatus() == 0){
 				ConfigEntity config = DevCacheUtils.getConfig(order.getUid());
 		 		// 微信支付jsapi 生成json
 				String nonceStr = CommonUtil.CreateNoncestr();
 				WxPayHelper wxPayHelper = new WxPayHelper();
 				wxPayHelper.setAppId(config.getAppId());
 				wxPayHelper.setMchId(config.getMchId());
 				wxPayHelper.SetParameter("nonce_str", nonceStr);
 				wxPayHelper.SetParameter("transaction_id", tradeNo);
 				wxPayHelper.setApiKey(config.getApiKey());
 				Map<String, String> result = wxPayHelper.orderquery();
 				if(result.get("xml.return_code").equals("SUCCESS")){ //{xml.time_end=20181229093627, xml.out_trade_no=201812290934867653, xml.result_code=SUCCESS, xml.sign=E6CCB2672048A9651EC13AB8A76E64BC, root.name=xml, xml.return_msg=OK, xml.trade_state_desc=支付成功, xml.total_fee=1, xml.openid=oLe7z0PJdls4IzUmS82rrHcq3bIA, xml.mch_id=1400343402, xml.fee_type=CNY, xml.trade_state=SUCCESS, xml.attach=, xml.cash_fee=1, xml.bank_type=CFT, xml.nonce_str=ML7XnRLAIwSTDb9M, xml.return_code=SUCCESS, xml.appid=wxad3e0062b1cbdaaf, xml.trade_type=JSAPI, xml.transaction_id=4200000232201812290072540704, xml.is_subscribe=N}
 					if(result.get("xml.result_code").equals("SUCCESS") && result.get("xml.trade_state").equals("SUCCESS")  && result.get("xml.total_fee").equals(String.format("%.0f",order.getPrice()*100))){
 	 					if(order.getStatus() == 0){
 	 						order.setStatus(1);
 	 	 	 				order.setTradeNo(tradeNo);
 	 	 	 				orderService.insertOrUpdate(order);
 	 	 	 				String today = DateUtils.format(new Date());
 	 	 	 				if(today.equals(DateUtils.format(order.getStartDate()))) {
 	 	 	 					HotelRoomEntity hotelRoom = hotelRoomService.selectById(order.getHotelRoomId());
 	 	 	 					hotelRoom.setStock(hotelRoom.getStock() - order.getNumber());
 	 	 	 					hotelRoomService.insertOrUpdate(hotelRoom);
 	 	 	 				}
 	 	 	 				
 	 	 	 				//给推荐人增加佣金
 	 	 	 				//开启营销功能
 	 	 	 				if(config.getRecommendCode() != null && config.getRecommendCode() == 1) {
 	 	 	 					if(StringUtils.isNotEmpty(order.getParentOpenid())) {
 	 	 	 						MemberEntity parent = memberService.getMemberByOpenid(order.getParentOpenid());
 	 	 	 						
 	 	 	 						//增加佣金
 	 	 	 						parent.setRecommendMoney(parent.getRecommendMoney() + config.getRecommendMoney());
 	 	 	 						memberService.insertOrUpdate(parent);
 	 	 	 						
 	 	 	 						//增加流水记录
 	 	 	 						RecommendMoneyLogEntity recommendMoneyLog = new RecommendMoneyLogEntity();
 	 	 	 						recommendMoneyLog.setUid(order.getUid());
 	 	 	 						recommendMoneyLog.setHotelId(order.getHotelId());
 	 	 	 						recommendMoneyLog.setHotelName(order.getHotelName());
	 	 	 	 					recommendMoneyLog.setHotelRoomId(order.getHotelRoomId());
	 	 	 	 					recommendMoneyLog.setHotelRoomName(order.getHotelRoomName());
	 	 	 	 					
		 	 	 	 				recommendMoneyLog.setOpenid(order.getOpenid());
		 	 	 	 				recommendMoneyLog.setName(order.getName());
			 	 	 	 			recommendMoneyLog.setAvatar(order.getAvatar());
			 	 	 	 			recommendMoneyLog.setMoney(config.getRecommendMoney());
				 	 	 	 		recommendMoneyLog.setParentOpenid(parent.getOpenid());
				 	 	 	 		recommendMoneyLog.setParentName(parent.getName());
				 	 	 	 		recommendMoneyLog.setOrderNo(order.getOrderNo());
				 	 	 	 		recommendMoneyLog.setCreateTime(order.getCreateTime());
				 	 	 	 		recommendMoneyLogService.insert(recommendMoneyLog);
 	 	 	 					}
 	 	 	 					
 	 	 	 				}
 	 	 	 				
 	 	 	 				
 	 	 	 				//打印预订订单小票
 	 	 	 				List<PrinterEntity> printerList = printerService.queryPrinterList(order.getHotelId());
 	 	 	 				List<String> openids = Lists.newArrayList();
 	 	 	 				openids.add(order.getOpenid());
 	 	 	 				List<Map> openidList = orderService.statOrderList(openids);
 	 	 	 				Object count = 0;
 	 	 	 				if(openidList != null && openidList.size() > 0) {
 	 	 	 					count = openidList.get(0).get("count");
	 	 	 	 			}
 	 	 	 				for (PrinterEntity printer : printerList) {
 	 	 	 					PrinterUtils.print(printer.getSn(), order, count);
							}
 	 	 	 				
 	 	 	 				//赠送早餐券
 	 	 	 				HotelRoomEntity hotelRoom = hotelRoomService.selectById(order.getHotelRoomId());
 	 	 	 				if(hotelRoom.getIsGiveCoupon() != null && hotelRoom.getIsGiveCoupon() == 1) {
 	 	 	 					int days = DateUtils.differentDays(order.getStartDate(), order.getEndDate());
 	 	 	 				
			 	 	 	 		System.out.println(days);
			 	 	 	 		for (int i = 0; i < days; i++) {
			 	 	 	 			int number = order.getNumber()*hotelRoom.getGiveCouponNumber();
			 	 	 	 			for (int j = 0; j < number; j++) {
					 	 	 	 		BreakfastCouponEntity breakfastCoupon = new BreakfastCouponEntity();
				    					breakfastCoupon.setUid(order.getUid());
				    					breakfastCoupon.setHotelId(order.getHotelId());
				    					breakfastCoupon.setHotelName(order.getHotelName());
				    					breakfastCoupon.setHotelRoomId(order.getHotelRoomId());
				    					breakfastCoupon.setHotelRoomName(order.getHotelRoomName());
				    					breakfastCoupon.setOpenid(order.getOpenid());
				    					breakfastCoupon.setName(order.getName());
				    					breakfastCoupon.setNickname(order.getNickname());
				    					breakfastCoupon.setName(order.getName());
				    					breakfastCoupon.setMobile(order.getMobile());
				    					breakfastCoupon.setAvatar(order.getAvatar());
				    					breakfastCoupon.setStatus(0);
				    					breakfastCoupon.setUsedDate(DateUtils.addDateDays(order.getStartDate(), (i+1)));
				    					breakfastCoupon.setCreateTime(new Date());
				    					breakfastCouponService.insert(breakfastCoupon);
			 	 	 	 			}
			 	 	 	 		}
			 	 	 	 		DevUtils.sendTemplateMessage(order.getUid(), order.getOpenid(),order.getPrepayId());
 	 	 	 				}
	 	 	 	 			
 	 					}
 	 				}
				}
 			}
 			resXml = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
 		} else {
 			resXml = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[支付失败]]></return_msg></xml>";
 		}
 		return resXml;
 	}
 	
 	/**
 	 * 查询订单详情
 	 * http://localhost/api/hotel/get_order?orderNo=*
 	 * @param orderNo
 	 * @return
 	 */
 	@SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "get_order")
    public R get_order(@RequestParam(value="orderNo",defaultValue="")String orderNo) {
 		OrderEntity order = orderService.getByOrderNo(orderNo);
 		if(order != null) {
 			return R.ok().put("order", order).put("hotel", hotelService.getHotel(order.getHotelId()));
 		}else {
 			return R.error("订单号不存在！");
 		}
    } 
 	
 	/**
 	 * 查询我的订单列表
 	 * http://localhost/admin/api/hotel/query_order_list?openid=ogDOQ4hhxSTBe4z8fyTtjBNy-0lgpageNo=1&pageSize=5
 	 * @param openid
 	 * @param pageNo
 	 * @param pageSize
 	 * @return
 	 */
 	@RequestMapping(value = "query_order_list")
	public R query_order_list(@RequestParam(value="openid",defaultValue="")String openid,
			@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,
			@RequestParam(value="pageSize",defaultValue="20")Integer pageSize) {
		if(StringUtils.isNotEmpty(openid)){
			//验证新手机号 的 验证码
			List<Map> list = orderService.queryOrderList(openid, pageNo, pageSize);
			if(list != null && list.size() > 0){
				return R.ok().put("l", list);
			}else{
				if(pageNo == 1){
					return R.error(103,"暂无数据");
				}else{
					return R.error(104,"暂无数据");
				}
			}
		}else{
			return R.error("参数异常!");
		}
	}
 	
 	
 	
 	/********************************************押金管理  start**************************************************/
 	/**
 	 * 获取我的押金
 	 * http://localhost/api/hotel/get_my_earnest_money?openid=
 	 * @param order
 	 * @param request
 	 * @return
 	 */
 	 @SuppressWarnings({ "unchecked", "rawtypes" })
     @RequestMapping(value = "get_my_earnest_money")
     public R get_my_earnest_money(@RequestParam(value="openid",defaultValue="")String openid) {
         Double totalMoney = earnestMoneyOrderService.getMyTotalMoney(openid);
         if(totalMoney == null) {
        	 totalMoney = 0D;
         }
         return R.ok().put("totalMoney", String.format("%.2f", totalMoney));
     }
 	
 	 /**
 	  * 创建押金订单
 	  * @param order
 	  * @param start
 	  * @param end
 	  * @param request
 	  * @return
 	  */
 	 @SuppressWarnings({ "unchecked", "rawtypes" })
     @RequestMapping(value = "create_earnest_money_order")
     public R create_earnest_money_order(EarnestMoneyOrderEntity order,
 			HttpServletRequest request) {
         try {
        	System.out.println("酒店编号："+order.getHotelId());
         	MemberEntity member = memberService.getMemberByOpenid(order.getOpenid());
     		if(member !=null && StringUtils.isNotEmpty(member.getMobile())){
     			ConfigEntity config = DevCacheUtils.getConfig(order.getUid());
 
 				//订单号
 	        	String orderNo = CommonUtil.getOrderNo(6);
 	        	//商品名称
 	        	String body = order.getPrice()+"元押金";
 	        	//金额
 	        	Double money = order.getPrice();

 				order.setUid(config.getUid());
 				order.setConfigId(config.getId());
 				order.setConfigName(config.getName());
 		
 				
 				order.setName(member.getName());
 				order.setNickname(member.getNickname());
 				order.setMobile(member.getMobile());
 				order.setAvatar(member.getAvatar());
 				order.setStatus(0);
 				order.setOrderNo(orderNo);
 				order.setCreateTime(new Date());
 				order.setRefundFee(0D);
 				HotelEntity hotel = hotelService.getHotel(order.getHotelId());
 				if(hotel != null && hotel.getId() != null && hotel.getId() > 0) {
 					order.setHotelId(hotel.getId());
 					order.setHotelName(hotel.getName());
 				}
 				
 				
 				Map jsApi = create_earnest_money_js_api(config.getUid(), body, orderNo, money, order.getOpenid(), request);
 				order.setPrepayId(jsApi.get("package").toString().replace("prepay_id=", ""));
 				earnestMoneyOrderService.insert(order);
     			return R.ok("OK").put("orderNo", orderNo).put("jsapi", jsApi);
     		}else{
     			return R.error(101,"请注册会员！");
     		}
 			
 		} catch (Exception e) {
 			e.printStackTrace();
 			return R.error("参数异常!");
 		}
     } 
 	
 	
 	/**
      * 生成访问小程序支付jsapi
      * 
      * @param request
      * @return
      */
  	@SuppressWarnings("rawtypes")
 	private Map create_earnest_money_js_api(Long uid,String body,String orderNo,Double money,String openid,HttpServletRequest request)throws Exception {
 		ConfigEntity config = DevCacheUtils.getConfig(uid);
  		// 微信支付jsapi 生成json
 		String nonceStr = CommonUtil.CreateNoncestr();
 		String basePath = request.getScheme() + "://"
 				+ request.getServerName() + request.getContextPath();
 		WxPayHelper wxPayHelper = new WxPayHelper();
 		wxPayHelper.setAppId(config.getAppId());
 		wxPayHelper.setMchId(config.getMchId());
 		
 		wxPayHelper.SetParameter("nonce_str", nonceStr);
 		wxPayHelper.SetParameter("body", body);
 		wxPayHelper.SetParameter("out_trade_no", orderNo);
 		wxPayHelper.SetParameter("total_fee",String.format("%.0f",money*100));
 		wxPayHelper.SetParameter("spbill_create_ip",
 				IPUtils.getIpAddr(request));
 		wxPayHelper.SetParameter("notify_url", basePath
 				+ "/api/hotel/wx_earnest_money_notify");
 		wxPayHelper.SetParameter("trade_type", "JSAPI");
 		wxPayHelper.SetParameter("openid", openid);
 		wxPayHelper.setApiKey(config.getApiKey());
 		return wxPayHelper.createPayByJSAPI();
  	}
  	
  	/**
  	 * 微信支付回调
  	 * http://localhost:8080/admin/api/member/wxNotify
  	 * @param request
  	 * @param response
  	 * @return
  	 * @throws Exception
  	 */
  	@RequestMapping(value = "wx_earnest_money_notify")
  	public String wx_earnest_money_notify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  		//<xml><appid><![CDATA[wxad3e0062b1cbdaaf]]></appid><bank_type><![CDATA[CFT]]></bank_type><cash_fee><![CDATA[1]]></cash_fee><fee_type><![CDATA[CNY]]></fee_type><is_subscribe><![CDATA[N]]></is_subscribe><mch_id><![CDATA[1400343402]]></mch_id><nonce_str><![CDATA[VQweZcmzsBxNlSyH]]></nonce_str><openid><![CDATA[oLe7z0PJdls4IzUmS82rrHcq3bIA]]></openid><out_trade_no><![CDATA[201812290934867653]]></out_trade_no><result_code><![CDATA[SUCCESS]]></result_code><return_code><![CDATA[SUCCESS]]></return_code><sign><![CDATA[ACE389049C3102FE95746469BE2BA913]]></sign><time_end><![CDATA[20181229093627]]></time_end><total_fee>1</total_fee><trade_type><![CDATA[JSAPI]]></trade_type><transaction_id><![CDATA[4200000232201812290072540704]]></transaction_id></xml>
  		StringBuffer stringBuffer = new StringBuffer();
  		BufferedReader bReader = request.getReader();
  		String line = "";
  		while ((line = bReader.readLine()) != null) {
  			stringBuffer.append(line);
  		}
  		Map<String, String> xmlMap = XMLUtils.xml2Map(stringBuffer.toString());

  		String resXml = null;

  		if ("SUCCESS".equals(xmlMap.get("xml.result_code"))) {
  			String orderNo = xmlMap.get("xml.out_trade_no");
  			String tradeNo = xmlMap.get("xml.transaction_id");
  			
  			EarnestMoneyOrderEntity order =  earnestMoneyOrderService.getByOrderNo(orderNo);
  			if(order != null && order.getStatus() != null && order.getStatus() == 0){
  				ConfigEntity config = DevCacheUtils.getConfig(order.getUid());
  		 		// 微信支付jsapi 生成json
  				String nonceStr = CommonUtil.CreateNoncestr();
  				WxPayHelper wxPayHelper = new WxPayHelper();
  				wxPayHelper.setAppId(config.getAppId());
  				wxPayHelper.setMchId(config.getMchId());
  				wxPayHelper.SetParameter("nonce_str", nonceStr);
  				wxPayHelper.SetParameter("transaction_id", tradeNo);
  				wxPayHelper.setApiKey(config.getApiKey());
  				Map<String, String> result = wxPayHelper.orderquery();
  				if(result.get("xml.return_code").equals("SUCCESS")){ //{xml.time_end=20181229093627, xml.out_trade_no=201812290934867653, xml.result_code=SUCCESS, xml.sign=E6CCB2672048A9651EC13AB8A76E64BC, root.name=xml, xml.return_msg=OK, xml.trade_state_desc=支付成功, xml.total_fee=1, xml.openid=oLe7z0PJdls4IzUmS82rrHcq3bIA, xml.mch_id=1400343402, xml.fee_type=CNY, xml.trade_state=SUCCESS, xml.attach=, xml.cash_fee=1, xml.bank_type=CFT, xml.nonce_str=ML7XnRLAIwSTDb9M, xml.return_code=SUCCESS, xml.appid=wxad3e0062b1cbdaaf, xml.trade_type=JSAPI, xml.transaction_id=4200000232201812290072540704, xml.is_subscribe=N}
  					if(result.get("xml.result_code").equals("SUCCESS") && result.get("xml.trade_state").equals("SUCCESS")  && result.get("xml.total_fee").equals(String.format("%.0f",order.getPrice()*100))){
  	 					if(order.getStatus() == 0){
  	 						order.setStatus(1);
  	 	 	 				order.setTradeNo(tradeNo);
  	 	 	 				earnestMoneyOrderService.insertOrUpdate(order);
  	 	 	 				
	  	 	 	 			List<PrinterEntity> printerList = printerService.queryPrinterList(order.getHotelId());
	 	 	 				
	 	 	 				for (PrinterEntity printer : printerList) {
	 	 	 					PrinterUtils.yajin(printer.getSn(), order);
	 	 	 					PrinterUtils.yajin(printer.getSn(), order);
	 	 	 				}
  	 					}
  	 				}
 				}
  			}
  			resXml = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
  		} else {
  			resXml = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[支付失败]]></return_msg></xml>";
  		}
  		return resXml;
  	}
 	/********************************************押金管理  end****************************************************/
 	
 	
 	/********************************************早餐券管理  start**************************************************/
  	/**
  	 * http://localhost/api/hotel/query_my_coupon_list?openid=1&cityId=1&pageNo=1&pageSize=10
  	 * @param openid
  	 * @param pageNo
  	 * @param pageSize
  	 * @return
  	 */
	@RequestMapping(value = "query_my_coupon_list")
	public R query_my_coupon_list(@RequestParam(value="openid",defaultValue="")String openid,
			@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,
			@RequestParam(value="pageSize",defaultValue="20")Integer pageSize) {
		if(StringUtils.isNotEmpty(openid)){
			List<Map> list = breakfastCouponService.queryMyCouponList(openid, pageNo, pageSize);
			if(list != null && list.size() > 0){
				return R.ok().put("l", list);
			}else{
				if(pageNo == 1){
					return R.error(103,"暂无数据");
				}else{
					return R.error(104,"暂无数据");
				}
			}
		}else{
			return R.error("参数异常!");
		}
	}
	
	@RequestMapping(value = "query_today_coupon_list")
	public R query_today_coupon_list(@RequestParam(value="openid",defaultValue="")String openid) {
		if(StringUtils.isNotEmpty(openid)){
			List<Map> list = breakfastCouponService.queryTodayCouponList(openid);
			return R.ok().put("l", list);
		}else{
			return R.error("参数异常!");
		}
	}
	
	/**
	 * http://localhost/api/hotel/hexiao?openid=ogDOQ4hhxSTBe4z8fyTtjBNy-0lg&&couponId=06c34e99618d49ed876f5e41b48a6d81
	 * @param openid
	 * @param couponId
	 * @return
	 */
	@RequestMapping(value = "hexiao")
	public R hexiao(@RequestParam(value="openid",defaultValue="")String openid,
			@RequestParam(value="couponId",defaultValue="")String couponId,
			@RequestParam(value="code",defaultValue="")String code) {
		if(StringUtils.isNotEmpty(openid)){
			
			BreakfastCouponEntity coupon = breakfastCouponService.selectById(couponId);
			if(coupon != null && StringUtils.isNotEmpty(coupon.getId())){
				if(coupon.getStatus() == 1) {
					return R.error("该早餐券已使用");
				}else {
					if((DateUtils.format(new Date())).equals(DateUtils.format(coupon.getUsedDate()))) {
						HotelEntity hotel = hotelService.selectById(coupon.getHotelId());
						if(StringUtils.isNotEmpty(code) && hotel.getCode().equals(code)) {
							coupon.setStatus(1);
							coupon.setHexiaoTime(new Date());
							breakfastCouponService.insertOrUpdate(coupon);
							return R.ok("核销成功");
						}else {
							return R.error("核销失败，密码错误");
						}
					}else {
						return R.error("该早餐券已失效");
					}
				}
			}else{
				return R.error("该早餐券不存在");
			}
		}else{
			return R.error("参数异常!");
		}
	}
 	/********************************************早餐券管理  end****************************************************/
	
	/********************************************发票管理  start****************************************************/
	/**
	 * /api/hotel/query_company_list?keyword=keyword
	 * @param keyword
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @PostMapping(value = "query_company_list")
    public R query_company_list(@RequestParam(value="keyword",defaultValue="")String keyword) {
        try {
        	String param = "keyWord="+keyword;
        	String result = HttpRequest.sendPost("http://songba.hbweiyinqing.cn/songbadaodian/f/CommonController/getInfoByKeyword", param);
        	JSONObject json = JSONObject.fromObject(result);
        	return R.ok().put("l", json.getJSONArray("l"));
		} catch (Exception e) {
			return R.error("参数异常!");
		}
    } 
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @PostMapping(value = "get_company")
    public R get_company(@RequestParam(value="companyIdentity",defaultValue="")String companyIdentity) {
        try {
        	String param = "companyIdentity="+companyIdentity;
        	String result = HttpRequest.sendPost("http://songba.hbweiyinqing.cn/songbadaodian/f/CommonController/getInfoByCompanyIdentity", param);
        	JSONObject json = JSONObject.fromObject(result);
        	return R.ok().put("i", json.getJSONObject("i"));
		} catch (Exception e) {
			return R.error("参数异常!");
		}
    } 
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @PostMapping(value = "add_invoice")
    public R add_invoice(InvoiceEntity invoice,
			HttpServletRequest request) {
        try {
        	String type = invoice.getType();
        	if(StringUtils.isNotEmpty(type)) {
        		if(StringUtils.isEmpty(invoice.getMoney())) {
        			return R.error("请选择开票金额");
        		}
        		if(StringUtils.isEmpty(invoice.getName())) {
        			return R.error("请选择发票抬头");
        		}
        		if(StringUtils.isEmpty(invoice.getTaxCode())) {
        			return R.error("请选择税号");
        		}
        		if(type.equals("2") && StringUtils.isEmpty(invoice.getAddress())) {
        			return R.error("请选择单位地址");
        		}
        		if(type.equals("2") && StringUtils.isEmpty(invoice.getBank())) {
        			return R.error("请选择开户银行");
        		}
        		if(type.equals("2") && StringUtils.isEmpty(invoice.getMobile())) {
        			return R.error("请选择公司电话");
        		}
        		if(type.equals("2") && StringUtils.isEmpty(invoice.getBankAccount())) {
        			return R.error("请选择银行账户");
        		}
        		if(type.equals("3") && StringUtils.isEmpty(invoice.getEmail())) {
        			return R.error("请选择电子邮件");
        		}
        		
        		MemberEntity member = memberService.getMemberByOpenid(invoice.getMemberOpenid());
        		if(member !=null && StringUtils.isNotEmpty(member.getMobile())){
        			HotelEntity hotel = hotelService.selectById(invoice.getHotelId());
        			invoice.setUid(hotel.getUid());
        			invoice.setConfigId(hotel.getConfigId());
        			invoice.setConfigName(hotel.getConfigName());
        			invoice.setMemberId(member.getId());
        			invoice.setMemberMobile(member.getMobile());
        			invoice.setMemberName(member.getName());
        			invoice.setHotelName(hotel.getName());
        			invoice.setCreateTime(new Date());
        			invoiceService.insert(invoice);
        			
        			List<PrinterEntity> printerList = printerService.queryPrinterList(invoice.getHotelId());
    	 				
     				for (PrinterEntity printer : printerList) {
     					PrinterUtils.yuyuefapiao(printer.getSn(), invoice);
     				}
            		return R.ok("添加发票成功");

        		}else{
        			return R.error(101,"请注册会员！");
        		}
        	}else {
        		return R.error("请选择发票类型");
        	}
        	
			
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("参数异常!");
		}
    } 
	/********************************************发票管理  end****************************************************/
	
	
	
	/********************************************营销活动  start****************************************************/
	/**
	 * http://182s163a59.imwork.net/api/hotel/get_recommend_info?uid=1&openid=ogDOQ4hhxSTBe4z8fyTtjBNy-0lg
	 * @param companyIdentity
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @GetMapping(value = "get_recommend_info")
    public R get_recommend_info(Long uid,String openid) {
    	ConfigEntity config = DevCacheUtils.getConfig(uid);
    	MemberEntity member = memberService.getMemberByOpenid(openid);
    	Map map = withdrawalLogService.getLastWithdrawal(openid);
    	map.put("isRecommend", config.getRecommendCode());
    	map.put("recommendTip", config.getRecommendTip().replace("\n", "<br/>"));
    	map.put("money", member.getRecommendMoney());
    	map.put("withdrawalTip", config.getWithdrawalTip().replace("\n", "<br/>"));
    	
    	
    	return R.ok().put("i", map);
		
    } 
	/**
	 * http://localhost/api/hotel/recommend_poster?uid=1&openid=ogDOQ4hhxSTBe4z8fyTtjBNy-0lg
	 * @param uid
	 * @param openid
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @GetMapping(value = "recommend_poster")
    public R recommend_poster(Long uid,String openid,
		HttpServletRequest request,HttpServletResponse response) {
    	ConfigEntity config = DevCacheUtils.getConfig(uid);
    	String qrcode = "https://laikehttps.hbweiyinqing.cn/yajin/index"+uid+"/?parentOpenid="+openid;
    	String backgroundFilePath = DevUtils.getConfigResourceSavePath()+File.separator + config.getRecommendPic();
    	String pic = ImageUtils.createImage(config,qrcode,backgroundFilePath);
    	return R.ok().put("pic", "data:image/png;base64,"+pic);
		
    } 
	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
    @GetMapping(value = "set_parent")
    public R set_parent(String openid,String parentOpenid) {
    	MemberEntity member = memberService.getMemberByOpenid(openid);
    	MemberEntity parent = memberService.getMemberByOpenid(parentOpenid);
    	if(member != null && member.getId() != null && member.getId() > 0) {
    		member.setParentOpenid(parent.getOpenid());
        	member.setParentName(parent.getName());
        	memberService.insertOrUpdate(member);
        	return R.ok("设置成功！");
    	}else {
    		return R.error("设置失败， 请注册");
    	}
    	
		
    } 
	
	/**
 	 * 1.我的推荐佣金列表
 	 * @param openid
 	 * @param pageNo
 	 * @param pageSize
 	 * @return
 	 */
 	@RequestMapping(value = "query_recomment_list")
	public R query_recomment_list(@RequestParam(value="openid",defaultValue="")String openid,
			@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,
			@RequestParam(value="pageSize",defaultValue="20")Integer pageSize) {
		if(StringUtils.isNotEmpty(openid)){
			List<Map> list = recommendMoneyLogService.queryRecommentList(openid, pageNo, pageSize);
			if(list != null && list.size() > 0){
				return R.ok().put("l", list);
			}else{
				if(pageNo == 1){
					return R.error(103,"暂无数据");
				}else{
					return R.error(104,"暂无数据");
				}
			}
		}else{
			return R.error("参数异常!");
		}
	}
	/********************************************营销活动  end******************************************************/
	
	/********************************************提现功能  start****************************************************/
	
 	@RequestMapping(value = "withdrawal")
	public R withdrawal(WithdrawalLogEntity withdrawalLog) {
		if(StringUtils.isNotEmpty(withdrawalLog.getOpenid())){
			if(StringUtils.isEmpty(withdrawalLog.getName())) {
    			return R.error("请选择姓名");
    		}
    		if(withdrawalLog.getMoney() == null) {
    			return R.error("请选择提现金额");
    		}
    		if(StringUtils.isEmpty(withdrawalLog.getBank())) {
    			return R.error("请选择开户银行");
    		}
    		if(StringUtils.isEmpty(withdrawalLog.getBankAccount())) {
    			return R.error("请选择开户账号");
    		}
    		
			
			MemberEntity member = memberService.getMemberByOpenid(withdrawalLog.getOpenid());
			ConfigEntity config = DevCacheUtils.getConfig(member.getUid());
			if(withdrawalLog.getMoney() < config.getWithdrawalMinMoney()) {
				return R.error("提现失败,提现金额不能小于"+config.getWithdrawalMinMoney()+"元");
			}
			if(withdrawalLog.getMoney() > member.getRecommendMoney()) {
				return R.error("提现失败,可提现金额不足");
			}
			member.setRecommendMoney(member.getRecommendMoney() - withdrawalLog.getMoney());
			memberService.insertOrUpdate(member);
			withdrawalLog.setUid(member.getUid());
			withdrawalLog.setNickname(member.getNickname());
			withdrawalLog.setMobile(member.getMobile());
			withdrawalLog.setStatus("0");
			withdrawalLog.setCreateTime(new Date());
			withdrawalLogService.insert(withdrawalLog);
			return R.ok("提现成功，正在审核中");
			
		}else{
			return R.error("参数异常!");
		}
	}
 	
 	/**
 	 * 1.我的提现记录
 	 * @param openid
 	 * @param pageNo
 	 * @param pageSize
 	 * @return
 	 */
 	@RequestMapping(value = "query_withdrawal_log_list")
	public R query_withdrawal_log_list(@RequestParam(value="openid",defaultValue="")String openid,
			@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,
			@RequestParam(value="pageSize",defaultValue="20")Integer pageSize) {
		if(StringUtils.isNotEmpty(openid)){
			List<Map> list = withdrawalLogService.queryWithdrawalLogList(openid, pageNo, pageSize);
			if(list != null && list.size() > 0){
				return R.ok().put("l", list);
			}else{
				if(pageNo == 1){
					return R.error(103,"暂无数据");
				}else{
					return R.error(104,"暂无数据");
				}
			}
		}else{
			return R.error("参数异常!");
		}
	}
	/********************************************提现功能  end******************************************************/
}
